package com.heima.mvplibrary.base;


import android.util.Log;

import com.heima.mvplibrary.api.Constants;
import com.heima.mvplibrary.mvp.IPresenter;
import com.heima.mvplibrary.mvp.IView;

import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

public class BasePresenter<V extends IView> implements IPresenter<V> {

    private static final String TAG = "BasePresenter";

    private WeakReference<V> v;

    public SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public void attachView(V view) {
        v = new WeakReference<>(view);
    }

    @Override
    public void detachView() {
        if (v.get() != null) {
            v.clear();
        }
        v = null;
    }

    @Override
    public V getV() {
        if (v == null || v.get() == null) {
            return null;
        }
        return v.get();
    }

    @Override
    public boolean isAttachedV() {
        return v != null && v.get() != null;
    }





    public interface OnRespListener<M> {
        void onSuccess(M value);

        void onFailed(Throwable e);

        void onLog(M value,Throwable e);
    }



}
